{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "conceptual-israel",
   "metadata": {},
   "source": [
    "# Problem 14.11 Pressure Rise In a Storage Tank Upon Heating"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "detected-spider",
   "metadata": {},
   "source": [
    "500 kg of propylene is contained in a 1 m^3 vessel stored at 30 °C. The vessel is heated - from solar radiation in the problem statement. What is the initial pressure? \n",
    "\n",
    "The safety valve of the tank activates at 60 bar. If the cooling system is disabled, what temperature will the contents of the vessel be when the valve actuates?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "checked-authority",
   "metadata": {},
   "source": [
    "## Solution\n",
    "\n",
    "This is straightforward - an initial solution with total volume, mass, and temperature specified, followed by solving for the end temperature to obtain a specified pressure.\n",
    "\n",
    "From experience the vessel is known to be liquid. Because of that, we can skip the flash calculations and work directly with the liquid phase object. That is normally much faster than the flash calculations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "focal-eugene",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The initial pressure is  1.979 MPa\n",
      "The end tempererature is  311.102 K\n"
     ]
    }
   ],
   "source": [
    "from scipy.constants import bar, hour\n",
    "from thermo import ChemicalConstantsPackage, PRMIX, CEOSLiquid, CoolPropLiquid, CEOSGas, CoolPropGas, FlashPureVLS\n",
    "fluid = 'propylene'\n",
    "constants, correlations = ChemicalConstantsPackage.from_IDs([fluid])\n",
    "\n",
    "T1 = 30 + 273.15\n",
    "P2 = 60*bar\n",
    "zs = [1]\n",
    "V_total = 1 # m^3\n",
    "m = 500 # kg\n",
    "\n",
    "backend = 'HEOS'\n",
    "gas = CoolPropGas(backend, fluid, T=T1, P=1e5, zs=zs)\n",
    "liquid = CoolPropLiquid(backend, fluid, T=T1, P=1e5, zs=zs)\n",
    "\n",
    "flasher = FlashPureVLS(constants, correlations, gas=gas, liquids=[liquid], solids=[])\n",
    "\n",
    "# Calculate the total number of moles\n",
    "moles = m/(1e-3*constants.MWs[0])\n",
    "# Calculate the molar volume\n",
    "Vm_initial = V_total/moles\n",
    "\n",
    "# We know the phase is liquid, so we can skip the flash and solve for the liquid at this state\n",
    "state_1 = liquid.to(T=T1, V=Vm_initial, zs=zs)\n",
    "print(f'The initial pressure is {state_1.P/1e6: .3f} MPa')\n",
    "\n",
    "state_2 = liquid.to(P=P2, V=Vm_initial, zs=zs)\n",
    "print(f'The end tempererature is {state_2.T: .3f} K')"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
